﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using OutlookBar;
using System.Data;
using OutlookBar.Components;
using CustomControl;
using AvalonDock;
using CMISLibrary.Libraries;
using busDanhMuc;
using BaocaoNPC.common;

namespace NPCUS_DanhMuc.Usercontrols
{
    /// <summary>
    /// Interaction logic for NPC_MENU.xaml
    /// </summary>
    public partial class NPC_MENU : UserControl
    {

        TreeViewItem itsel = new TreeViewItem();
        private DataSet dsResultTREE;
        private object dummyNode = null;

        DataSet ds;
        DataSet dsNPC_LIBRARY_Entity;
        DataSet dsNPC_MENU_Entity;
        DataTable dtBindData;
        cls_NPC_LIBRARY cls_LIBRARY = new cls_NPC_LIBRARY();
        cls_NPC_MENU cls_MENU = new cls_NPC_MENU();

        string id = "";
        string ten = "";
        string dienthoai = "";
        string strBtnClick = "";
        string strError = "";
        string strFind = "";
        int intDongFocus = 0;
        int intIDdong = 0;
        long intLIBID = -2;
        long intMENUID = -2;
        long intPARENTMENUID = -2;

        public NPC_MENU()
        {
            InitializeComponent();

            dsNPC_LIBRARY_Entity = new EntitiesDanhMuc.NPC_LIBRARY();
            dsNPC_MENU_Entity = new EntitiesDanhMuc.NPC_MENU();

            btnThemMoi.IsEnabled = false;
            btnSua.IsEnabled = false;
            btnXoa.IsEnabled = false;
            btnGhi.IsEnabled = false;
            btnHuy.IsEnabled = false;
            btnTimKiem.IsEnabled = true;

            rdbTrunggian.IsChecked = true;
            rdbChucnang.IsChecked = false;
            txtLIBNAME.IsEnabled = false;
            btnChon.IsEnabled = false;

            txtHEADER.IsEnabled = true;
            txtLIBNAME.IsReadOnly = true;
            txtLIBNAME_U.IsReadOnly = true;
            txtORDERNUMBER.IsEnabled = true;

        }

        public void showMessErrorOnView(string str)
        {
            Component.Validate.ValidationManager.showMessOnView(this, 3000, str, Component.Validate.ValidationManager.MESSEGER_TYPE.ERROR_MESSAGE);
        }
        public void showMessSucOnView(string str)
        {
            Component.Validate.ValidationManager.showMessOnView(this, 3000, str, Component.Validate.ValidationManager.MESSEGER_TYPE.SUCCESS_MESSAGE);
        }

        private void Fill_Data_Tree()
        {
            try
            {
                cls_NPC_MENU cls = new cls_NPC_MENU();

                TreeViewItem root = new TreeViewItem();
                //TreeNode node = null;
                dsResultTREE = new DataSet();
                dsResultTREE = GlobalServices.Service_NPCUS.select_NPC_MENU_All();                

                this.trvMenuChucNang.Items.Clear(); // xoa tree tru?c khi d? d? li?u m?i
                if (dsResultTREE == null)
                {
                    MessageBox.Show(" Không có phần tử nào trên cây !");
                    btnThemMoi.IsEnabled = false;
                    return;
                }
                DataView dv = new DataView(dsResultTREE.Tables[0]);
                //HeaderToImageConverter.Instance.ds = dsResultTREE.Copy();
                if (dv.Count == 0) // không có d? li?u không dua ra tree
                {
                    MessageBox.Show(" Không có phần tử nào trên cây !");
                    btnThemMoi.IsEnabled = false;
                    return;
                }

                btnThemMoi.IsEnabled = true;
                btnSua.IsEnabled = true;
                btnXoa.IsEnabled = true;
                dv.Sort = "PARENTMENUID,ORDERNUMBER";

                foreach (DataRowView dr in dv)
                {
                    TreeViewItem item = new TreeViewItem();
                    if (dr["PARENTMENUID"].ToString() == string.Empty)
                    {
                        item.Header = dr["HEADER"].ToString();
                        //if (dr["TTRANG_DONGCAT"].ToString() == "0") item.Foreground = Brushes.Red;
                        //if (dr["TTRANG_DONGCAT"].ToString == "0") item.Foreground = Brushes.;
                        item.Tag = dr["MENUID"].ToString();
                        item.FontWeight = FontWeights.Normal;
                        item.Items.Add(dummyNode);
                        item.Expanded += new RoutedEventHandler(folder_Expanded);
                        dsResultTREE.Tables[0].DefaultView.RowFilter = "PARENTMENUID = '" + dr["MENUID"].ToString() + "'";
                        //if (dsResultTREE.Tables[0].DefaultView.Count == 0) 
                        item.IsExpanded = true;
                        trvMenuChucNang.Items.Add(item);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }
        }
        private void folder_Expanded(object sender, RoutedEventArgs e)
        {
            TreeViewItem item = (TreeViewItem)sender;
            DataView dv = new DataView(dsResultTREE.Tables[0]);
            dv.Sort = "PARENTMENUID,ORDERNUMBER";
            if (item.Items.Count == 1 && item.Items[0] == dummyNode)
            {
                item.Items.Clear();
                try
                {
                    foreach (DataRowView dr in dv)
                    {
                        TreeViewItem subitem = new TreeViewItem();
                        if (dr["PARENTMENUID"].ToString() == item.Tag.ToString())
                        {
                            subitem.Header = dr["HEADER"].ToString();
                            subitem.Tag = dr["MENUID"].ToString();
                            //if (dr["TTRANG_DONGCAT"].ToString() == "0") subitem.Foreground = Brushes.Red;
                            subitem.FontWeight = FontWeights.Normal;
                            subitem.Items.Add(dummyNode);
                            subitem.Expanded += new RoutedEventHandler(folder_Expanded);
                            dsResultTREE.Tables[0].DefaultView.RowFilter = "PARENTMENUID = '" + dr["MENUID"].ToString() + "'";
                            if (dsResultTREE.Tables[0].DefaultView.Count == 0) subitem.IsExpanded = true;
                            item.Items.Add(subitem);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return;
                }
            }
        }

        private bool checkTextBoxIn()
        {
            if (txtHEADER.Text.ToString().Trim() == string.Empty)
            {
                showMessErrorOnView("Nhập tên Menu");
                txtHEADER.Focus();
                return false;
            }

            if (txtORDERNUMBER.Text.ToString().Trim() == string.Empty)
            {
                showMessErrorOnView("Nhập thứ tự hiển thị của Menu");
                txtORDERNUMBER.Focus();
                return false;
            }

            if (rdbChucnang.IsChecked == true)
            {
                if (txtLIBNAME_U.Text.ToString().Trim() == string.Empty)
                {
                    showMessErrorOnView("Chưa chọn chức năng !");
                    return false;
                }
            }

            return true;
        }

        private void CheckIsEnableButtonSuaXoa()
        {

            if (trvMenuChucNang.Items.Count > 0)
            {
                if (strBtnClick == "btnThemMoi" || strBtnClick == "SUA")
                {
                    btnSua.IsEnabled = false;
                    btnXoa.IsEnabled = false;
                }
                else
                {
                    btnSua.IsEnabled = true;
                    btnXoa.IsEnabled = true;
                }
            }
            else
            {
                btnSua.IsEnabled = false;
                btnXoa.IsEnabled = false;
            }
        }

        private bool checkPK()
        {
            DataSet dsTemp = GlobalServices.Service_NPCUS.select_NPC_MENU_by_ID(intMENUID);            

            if (dsTemp != null)
            {
                if (dsTemp.Tables[0].Rows.Count > 0)
                {

                    MessageBox.Show("ID " + intMENUID + " đã tồn tại !");
                    return true;
                }
                else return false;
            }
            else return false;

        }

        private void setCurrentData_grid()
        {
            DataRowView drv = dgrNPC_LIBRARY.SelectedItem as DataRowView;

            if (drv != null)
            {
                if (strBtnClick == "btnThemMoi" || strBtnClick == "SUA")
                {
                    intLIBID = Convert.ToInt64(drv.Row["LIBID"]);

                    txtLIBNAME.Text = drv.Row["LIBNAME"].ToString();
                }
                else
                {
                    btnThemMoi.IsEnabled = true;
                    btnSua.IsEnabled = true;

                    intLIBID = Convert.ToInt64(drv.Row["LIBID"]);

                    txtLIBNAME.Text = drv.Row["LIBNAME"].ToString();
                }
            }
        }

        private void setCurrentData_Tree()
        {
            itsel = trvMenuChucNang.SelectedItem as TreeViewItem;

            if (itsel != null)
            {
                if (strBtnClick == "btnThemMoi" || strBtnClick == "SUA")
                {

                }
                else
                {
                    txtHEADER.Text = itsel.Header.ToString();

                    intMENUID = Convert.ToInt64(itsel.Tag.ToString());

                    DataTable dt = dsResultTREE.Tables[0].Select("MENUID = '" + itsel.Tag.ToString() + "'").CopyToDataTable();

                    if (dt.Rows[0]["PARENTMENUID"].ToString() != string.Empty)
                    {
                        intPARENTMENUID = Convert.ToInt64(dt.Rows[0]["PARENTMENUID"].ToString());
                    }

                    txtORDERNUMBER.Text = dt.Rows[0]["ORDERNUMBER"].ToString();
                }
            }
        }

        private void setEntity_chucnang(string strBtnClick)
        {
            try
            {
                dsNPC_LIBRARY_Entity.Tables["NPC_LIBRARY"].Clear();
                DataRow dr = dsNPC_LIBRARY_Entity.Tables["NPC_LIBRARY"].NewRow();
                switch (strBtnClick)
                {
                    case "btnTimKiem":
                        dr["SUBDIVISIONID"] = "PA";

                        dr["LIBID"] = -1;

                        if (txtLIBNAME_S.Text.Trim().ToString() != string.Empty)
                        {
                            dr["LIBNAME"] = txtLIBNAME_S.Text.Trim().ToString();
                        }
                        else
                        {
                            dr["LIBNAME"] = " ";
                        }

                        dr["NAMESPACE"] = " ";

                        if (txtASSEMBLYNAME_S.Text.Trim().ToString() != string.Empty)
                        {
                            dr["ASSEMBLYNAME"] = txtASSEMBLYNAME_S.Text.Trim().ToString();
                        }
                        else
                        {
                            dr["ASSEMBLYNAME"] = " ";
                        }

                        dr["PRIORITY"] = 3;

                        dr["STATE"] = 1;

                        dr["CREATEDDATE"] = DateTime.Now.Date;

                        dr["CREATEDBY"] = "Admin";

                        break;
                }
                dsNPC_LIBRARY_Entity.Tables["NPC_LIBRARY"].Rows.Add(dr);
                dsNPC_LIBRARY_Entity.AcceptChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void setEntity(string strBtnClick)
        {
            try
            {
                dsNPC_MENU_Entity.Tables["NPC_MENU"].Clear();
                DataRow dr = dsNPC_MENU_Entity.Tables["NPC_MENU"].NewRow();
                switch (strBtnClick)
                {
                    case "btnGhi":
                        dr["SUBDIVISIONID"] = "PA";

                        if (rdbChucnang.IsChecked == true)
                        {
                            dr["LIBID"] = intLIBID;
                        }
                        else
                        {
                            dr["LIBID"] = null;
                        }

                        dr["MENUID"] = intMENUID;

                        dr["HEADER"] = txtHEADER.Text.Trim().ToString();

                        if (intMENUID == 0)
                        {
                            dr["PARENTMENUID"] = null;
                        }
                        else
                        {
                            dr["PARENTMENUID"] = intPARENTMENUID;
                        }

                        dr["ORDERNUMBER"] = Convert.ToInt16(txtORDERNUMBER.Text.Trim().ToString());

                        dr["CREATEDDATE"] = DateTime.Now.Date;

                        dr["CREATEDBY"] = "Admin";

                        dr["WORKFLOWID"] = "";

                        dr["MENU_PARAM"] = "";

                        break;

                    case "btnXoa":
                        dr["SUBDIVISIONID"] = "PA";

                        dr["LIBID"] = intLIBID;

                        dr["MENUID"] = intMENUID;

                        dr["HEADER"] = txtHEADER.Text.Trim().ToString();

                        dr["PARENTMENUID"] = intPARENTMENUID;

                        dr["ORDERNUMBER"] = Convert.ToInt16(txtORDERNUMBER.Text.Trim().ToString());

                        dr["CREATEDDATE"] = DateTime.Now.Date;

                        dr["CREATEDBY"] = "Admin";

                        dr["WORKFLOWID"] = "";

                        dr["MENU_PARAM"] = "";

                        break;

                    case "btnTimKiem":

                        break;
                    case "btnThemMoi":

                        break;
                }
                dsNPC_MENU_Entity.Tables["NPC_MENU"].Rows.Add(dr);
                dsNPC_MENU_Entity.AcceptChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void trvMenuChucNang_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            try
            {
                setCurrentData_Tree();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void dgrNPC_LIBRARY_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                setCurrentData_grid();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void cmdlaydulieu_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Fill_Data_Tree();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void btnThemMoi_Click(object sender, RoutedEventArgs e)
        {
            try
            {

                itsel = trvMenuChucNang.SelectedItem as TreeViewItem;
                if (itsel == null)
                {
                    return;
                }
                strBtnClick = "btnThemMoi";
                intPARENTMENUID = Convert.ToInt64(itsel.Tag.ToString());

                btnThemMoi.IsEnabled = false;
                btnSua.IsEnabled = false;
                btnXoa.IsEnabled = false;
                btnGhi.IsEnabled = true;
                btnHuy.IsEnabled = true;
                btnTimKiem.IsEnabled = true;

                rdbTrunggian.IsEnabled = true;
                rdbChucnang.IsEnabled = true;
                btnChon.IsEnabled = true;
                rdbTrunggian.IsChecked = true;

                txtLIBNAME.Clear();
                txtLIBNAME_U.Clear();

                txtHEADER.Text = "";
                txtORDERNUMBER.Text = "";

                txtHEADER.IsEnabled = true;
                txtORDERNUMBER.IsEnabled = true;

                trvMenuChucNang.IsEnabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void btnSua_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                itsel = trvMenuChucNang.SelectedItem as TreeViewItem;
                if (itsel == null)
                {
                    return;
                }
                strBtnClick = "SUA";
                //intPARENTMENUID = Convert.ToInt64(itsel.Tag.ToString());

                DataTable dt = dsResultTREE.Tables[0].Select("MENUID = '" + itsel.Tag.ToString() + "'").CopyToDataTable();
                if (dt.Rows[0]["LIBID"].ToString() == "-1")
                {
                    rdbTrunggian.IsChecked = true;
                    rdbChucnang.IsEnabled = false;
                }
                else
                    if (dt.Rows[0]["LIBID"].ToString() == string.Empty)
                    {
                        rdbTrunggian.IsChecked = true;
                        rdbChucnang.IsEnabled = false;
                    }
                    else
                        if (Convert.ToInt64(dt.Rows[0]["LIBID"].ToString()) >= 0)
                        {
                            rdbChucnang.IsChecked = true;
                        }

                txtORDERNUMBER.Text = dt.Rows[0]["ORDERNUMBER"].ToString();
                intPARENTMENUID = Convert.ToInt64(dt.Rows[0]["PARENTMENUID"].ToString());

                btnThemMoi.IsEnabled = false;
                btnSua.IsEnabled = false;
                btnXoa.IsEnabled = false;
                btnGhi.IsEnabled = true;
                btnHuy.IsEnabled = true;
                btnTimKiem.IsEnabled = true;

                txtHEADER.IsEnabled = true;
                txtORDERNUMBER.IsEnabled = true;

                trvMenuChucNang.IsEnabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void btnXoa_Click(object sender, RoutedEventArgs e)
        {
            this.Cursor = null;

            bool bolCheckDelete = false;
            strBtnClick = "XOA";
            if (MessageBox.Show("Bạn có chắc chắn xoá bản ghi có mã " + intMENUID.ToString() + " không?", "Thông báo", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                setEntity("btnXoa");

                DataSet dsTemp = GlobalServices.Service_NPCUS.select_NPC_MENU_by_PARENTID(intMENUID);
                

                if (dsTemp != null && dsTemp.Tables[0].Rows.Count > 0)
                {
                    MessageBox.Show("Menu này có các menu con, không xóa được ! ");
                    return;
                }

                bolCheckDelete = GlobalServices.Service_NPCUS.delete_NPC_MENU(dsNPC_MENU_Entity, ref strError);   


                if (bolCheckDelete == true)
                {
                    this.Cursor = null;
                    MessageBox.Show("Xoá dữ liệu thành công!", "Thông báo", MessageBoxButton.OK);
                    Fill_Data_Tree();

                }
                else
                {
                    this.Cursor = null;
                    if (strError.Contains("ORA-02292") == true)
                    {
                        MessageBox.Show("Mã số " + intLIBID.ToString() + " đã được sử dụng. Không thể xoá bản ghi này.", "Thông báo", MessageBoxButton.OK);
                    }
                }
            }
            CheckIsEnableButtonSuaXoa();
            strBtnClick = "";
            btnXoa.Focus();

        }

        private void btnGhi_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                this.Cursor = Cursors.Wait;

                bool checkInsert = false;

                // ========= Kiem tra du lieu nhap moi ========
                while (checkTextBoxIn() == false)
                {
                    this.Cursor = null;
                    return;
                }


                // ======= Thêm mới -> lấy nextSeq ======
                if (strBtnClick == "btnThemMoi")
                {
                    long nextSeq = 0;                    
                    nextSeq = GlobalServices.Service_NPCUS.GetNextSequence_menu(ref strError);                   
                    intMENUID = nextSeq;
                }

                // ======== Them moi -> kiem tra PK ========
                if (strBtnClick == "btnThemMoi")
                {
                    if (checkPK() == true)
                    {
                        this.Cursor = null;
                        MessageBox.Show("ID đã tồn tại!");
                        return;
                    }
                }

                setEntity("btnGhi");
                if (strBtnClick == "btnThemMoi")
                {
                    checkInsert = GlobalServices.Service_NPCUS.insert_NPC_MENU(dsNPC_MENU_Entity, ref strError); 
                }
                else
                {
                    checkInsert = GlobalServices.Service_NPCUS.update_NPC_MENU(dsNPC_MENU_Entity, ref strError);
                }


                // ===== Kiem tra Insert , Update thanh cong ? ===

                if (checkInsert == true)
                {
                    this.Cursor = null;

                    if (strBtnClick == "btnThemMoi")
                    { //====== them dong moi Insert vao dtHienthi =========
                        MessageBox.Show("Thêm mới thành công !");
                        Fill_Data_Tree();
                    }
                    else
                    {
                        MessageBox.Show("Sửa thành công !");
                        Fill_Data_Tree();
                    }

                    btnThemMoi.IsEnabled = true;
                    btnSua.IsEnabled = true;
                    btnXoa.IsEnabled = true;
                    btnGhi.IsEnabled = false;
                    btnHuy.IsEnabled = false;
                    btnTimKiem.IsEnabled = true;

                    txtHEADER.IsEnabled = false;
                    txtORDERNUMBER.IsEnabled = false;
                    rdbTrunggian.IsChecked = true;

                    trvMenuChucNang.IsEnabled = true;

                    if (strBtnClick == "SUA")
                    {
                        btnSua.Focus();
                    }
                    if (strBtnClick == "btnThemMoi")
                    {
                        btnThemMoi.Focus();
                    }

                    strBtnClick = "";
                }
                else
                {
                    this.Cursor = null;
                    MessageBox.Show("Không ghi được dữ liệu !" + strError.ToString());
                }


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }

        private void btnHuy_Click(object sender, RoutedEventArgs e)
        {
            btnThemMoi.IsEnabled = true;
            btnGhi.IsEnabled = false;
            btnHuy.IsEnabled = false;
            btnTimKiem.IsEnabled = true;

            if (trvMenuChucNang.Items.Count > 0)
            {
                btnSua.IsEnabled = true;
                btnXoa.IsEnabled = true;
            }
            else
            {
                btnSua.IsEnabled = false;
                btnXoa.IsEnabled = false;
            }

            setCurrentData_Tree();

            if (strBtnClick == "SUA")
            {
                btnSua.Focus();
            }
            else
                if (strBtnClick == "btnThemMoi")
                {
                    btnThemMoi.Focus();
                }

            txtHEADER.IsEnabled = false;
            txtORDERNUMBER.IsEnabled = false;
            rdbTrunggian.IsChecked = true;

            trvMenuChucNang.IsEnabled = true;

            strBtnClick = "";
        }

        private void btnTimKiem_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                this.Cursor = Cursors.Wait;

                setEntity_chucnang("btnTimKiem");
                if (dsNPC_LIBRARY_Entity.Tables["NPC_LIBRARY"].Rows.Count > 0)
                {
                    DataSet dsTemp;

                    dsTemp = GlobalServices.Service_NPCUS.select_NPC_LIBRARY_1by1(dsNPC_LIBRARY_Entity);                    

                    if (dsTemp != null)
                    {
                        strFind = "Yes";
                        DataTable dtHienthi = dsTemp.Tables[0].Copy();

                        if (dtHienthi.Rows.Count > 0)
                        {
                            dgrNPC_LIBRARY.ItemsSource = dtHienthi.DefaultView;

                            //CheckIsEnableButtonSuaXoa();

                            //======= nếu đang sửa -> tìm kiếm -> nếu trả về có dòng đang sửa -> focus về dòng đó trên Grid
                            for (int i = 0; i < dtHienthi.Rows.Count; i++)
                            {
                                if (int.Parse(dtHienthi.Rows[i]["LIBID"].ToString()) == intIDdong)
                                {
                                    intDongFocus = i;
                                }
                                else
                                {
                                    intDongFocus = -1;
                                }
                            }

                            ////====== Focus về dòng đang sửa - nếu có ======
                            //if (strBtnClick == "SUA")
                            //{
                            //    if (intDongFocus != -1)
                            //    {
                            //        dgrNPC_LIBRARY.SelectedIndex = intDongFocus; 
                            //    }
                            //}

                            if (strBtnClick != "btnThemMoi" || strBtnClick != "SUA")
                            {
                                dgrNPC_LIBRARY.SelectedIndex = 0;
                            }


                            CheckIsEnableButtonSuaXoa();
                            this.Cursor = null;
                        }
                    }
                    else
                    {
                        this.Cursor = null;
                        MessageBox.Show("Không tìm thấy theo điều kiện !");
                        strFind = "No";
                        txtLIBNAME_S.Focus();
                        e.Handled = true;
                    }

                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }

        private void btnChon_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtLIBNAME.Text.ToString() != string.Empty)
                {
                    txtLIBNAME_U.Text = txtLIBNAME.Text;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void rdbTrunggian_Checked(object sender, RoutedEventArgs e)
        {
            btnChon.IsEnabled = false;
            txtLIBNAME.IsEnabled = false;
        }

        private void rdbChucnang_Checked(object sender, RoutedEventArgs e)
        {
            txtLIBNAME.IsEnabled = true;
            btnChon.IsEnabled = true;
        }
    }
}
